package com.iwords.android;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @author BOLIN.HBC
 * @time 2011-3-13
 * @description Code-tools
 */
public class CodeUtils {

	private static final String DEFAULT_CODE = "utf-8";

	public static String encode(String value) {
		if (value == null || value.length() == 0) {
			return null;
		}
		try {
			return URLEncoder.encode(value, DEFAULT_CODE);
		} catch (UnsupportedEncodingException e) {
			System.out.println(e.getMessage());
		}
		return null;

	}

	public static String decode(String value) {
		if (value == null || value.length() == 0) {
			return null;
		}

		try {
			return URLDecoder.decode(value, DEFAULT_CODE);
		} catch (UnsupportedEncodingException e) {
			System.out.println("服务端返回的Json数组decode出错："+e.getMessage());
		} catch (Throwable t){
			t.printStackTrace();
		}
		return null;

	}

}
